package bma.common.netty.protobuf.common.impl;

import bma.common.langutil.pipeline.CommonPipelineContext;
import bma.common.netty.protobuf.common.PRequestFilter;
import bma.common.netty.protobuf.common.PRequestFilterChain;
import bma.common.netty.protobuf.core.PRequestContext;

public abstract class PRequestFilterPipelineContext extends
		CommonPipelineContext<PRequestFilter> implements PRequestFilterChain {

	public PRequestFilterPipelineContext(
			CommonPipelineContext<PRequestFilter> prev,
			CommonPipelineContext<PRequestFilter> next, String name,
			PRequestFilter item) {
		super(prev, next, name, item);
	}

	public abstract boolean processEnd(PRequestContext ctx);

	public boolean process(PRequestContext ctx) {
		if (item != null) {
			return item.process(this, ctx);
		}
		return next(ctx);
	}

	@Override
	public boolean next(PRequestContext ctx) {
		if (next != null) {
			return ((PRequestFilterPipelineContext) next).process(ctx);
		}
		return processEnd(ctx);
	}

}
